
/**
 * 页面跳转
 * @param url 要跳转页面的地址
 * @param [query] url后追加的参数
 * @param [in_new_tab=false] 是否在新页签打开页面
 * @example direct(url,query);
 */
export default function direct(url: string, query?: any, in_new_tab = false) {
	if (query) {
		const usp = new URLSearchParams();
		for (const k in query) {
			if (query.hasOwnProperty(k)) {
				usp.append(k, query[k]);
			}
		}
		const url_param = usp.toString();
		url = url.split('?')[0] + (url_param && url_param.length !== 0 ? '?' + url_param : '');
		// url = generate(query, url);
	}
	if (in_new_tab) {
		window.open(url);
	} else {
		// window.location.reload();
		window.location.assign(url);	// with histry
		// window.location.replace(url);	// without histry
	}
}
